package com.hu.bgp.server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;

import com.hu.bgp.exceptions.CommonException;

/**
 * Laad een configuratiebestand voor het platform
 * 
 * @author ejvos
 */
public class BgpConfiguration
{
	private String barRootPath;
	private String barExtractPath;
	private String barResourceDirName;
	private String barConfigFilename;
	private boolean barDirectActivate;
	private boolean doRebuildDatabase;

	public BgpConfiguration(ServletContext context)
	{
		InputStream is = context.getResourceAsStream("/WEB-INF/bgp.properties");
		if (is != null)
		{
			try
			{
				Properties p = new Properties();
				p.load(is);
				barRootPath = p.getProperty("bar.dir");
				barExtractPath = p.getProperty("bar.extract.dir");
				barResourceDirName = p.getProperty("bar.resource.dir.name");
				barConfigFilename = p.getProperty("bar.config.filename");
				barDirectActivate = Boolean.parseBoolean(p.getProperty("bar.directactivate"));
				doRebuildDatabase = Boolean.parseBoolean(p.getProperty("rebuild.database"));
			}
			catch (IOException e)
			{
				throw new CommonException(e);
			}
			try
			{
				is.close();
			}
			catch (IOException e)
			{
				// ignored
			}
		}
	}

	public String getBarRootPath()
	{
		return barRootPath;
	}

	public String getBarExtractPath()
	{
		return barExtractPath;
	}

	public String getBarResourceDirName()
	{
		return barResourceDirName;
	}

	public String getBarConfigFilename()
	{
		return barConfigFilename;
	}

	public boolean getBarDirectActivate()
	{
		return barDirectActivate;
	}

	public boolean getDoRebuildDatabase()
	{
		return doRebuildDatabase;
	}

	public String getResourcesUrlPrefix()
	{
		// DEBUG
		// HACK
		// TODO
		// FIXME put in configuration
		return "/resources/";
	}

	public String getPlayerClientUrlPrefix()
	{
		// DEBUG
		// HACK
		// TODO
		// FIXME put in configuration
		return "/playerclient/";
	}

	public String getScoreClientUrlPrefix()
	{
		// DEBUG
		// HACK
		// TODO
		// FIXME put in configuration
		return "/scoreclient/";
	}
}
